<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script>
        alert(document.cookie);
    </script>
</head>
<body>
<%
    Cookie[] cookies=request.getCookies();
    Cookie c=null;
    if (cookies!=null){
        for (int i=0;i<cookies.length;i++){
            if (cookies[i].getName().equals("count")){
                c=cookies[i];
                break;
            }
        }
    }
    if (c!=null){
        int count=0;
        count=Integer.parseInt(c.getValue());
        count++;
        c.setValue(String.valueOf(count));
        c.setMaxAge(84600*30);
        //?c.setHttpOnly(true);js无法获得
        response.addCookie(c);
        out.print("这是您第"+count+"次访问！");
    }else {
        Cookie cookie=new Cookie("count","1");
        cookie.setMaxAge(84600*30);
        response.addCookie(cookie);
        out.print("您这是第1次访问");
    }
%>

</body>
</html>
